<%-- 
    Document   : searchStaff
    Created on : Jul 8, 2012, 3:38:03 PM
    Author     : Home
--%>

<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="dbTool.myConnection"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="dbTool.functions"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>add Student Page</title>
    </head>
    <body>
        <%
            int searchBy = Integer.parseInt(request.getParameter("searchBy"));
            String search = request.getParameter("search");
            functions f = new functions();
            if (searchBy == 1) {
                try {
                    int id = Integer.parseInt(search);
                    ResultSet rSeafrch = null;
                    rSeafrch  = f.viewStaffByID(id);

                    if (rSeafrch == null) {
                        out.print("<script>alert('No staff with ID: " + search + "!');window.location='staff.jsp';</script>");                        
                    } else {
                        out.print("<script>window.location='staff.jsp?id=" + search + "';</script>");
                    }
                } catch (Exception e) {
                    System.out.println(e);
                    out.print("<script>alert('Error search!"+e+"');window.location='staff.jsp';</script>");
                }

            } else {
                ResultSet rsSearch = null;
                rsSearch = f.viewStaffByAcc(search);
                if (rsSearch == null) {
                    out.print("<script>alert('No staff with account: " + search + "!');window.location='staff.jsp';</script>");
                } else {
                    rsSearch.next();
                    int id = rsSearch.getInt("id");
                    String sID = id + "";
                    out.print("<script>window.location='staff.jsp?id=" + sID + "';</script>");                    
                }

            }         
        %>
    </body>
</html>

